//
//  CommonViewController.m
//  BaseLib
//
//  Created by CPX on 2018/8/30.
//

#import "CommonViewController.h"
#import "MBProgressTool.h"
#import "Firebase.h"

/**
 基类控制器实现
 @author yzl
 */
@interface CommonViewController ()

@end

@implementation CommonViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self initRegister];
    [self initUI];
    [self loadData];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setStatusBarLight:self.statusBarIsLight animate:NO];
}

- (void)initRegister{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppLayoutDirectionSettingChanged:) name:@"direction_layout_change" object:nil];
}

- (void)initUI{
    [self.navigationController setNavigationBarHidden:YES];
    self.view.backgroundColor = [UIColor whiteColor];
    [self initViews];
    [self initNavigation];
    [self initOtherViews];
}

- (void)initViews{
    
}

- (void)initNavigation{
    
}

- (void)initOtherViews{
    
}

- (void)initDefaultNavigation{
    self.myNavigationBar = [MyNavigationBar new];
    [self.myNavigationBar.backButton addTarget:self action:@selector(onLeftButtonTouched) forControlEvents:UIControlEventTouchUpInside];
    self.myNavigationBar.tag = 10000;
//    self.myNavigationBar.layer.zPosition = 10000;
    [self.view addSubview:self.myNavigationBar];
}

- (void)loadData{
    
}

- (void)setStatusBarLight:(BOOL)isLight animate:(BOOL)isAnimate{
    [[UIApplication sharedApplication] setStatusBarStyle:isLight?UIStatusBarStyleLightContent:UIStatusBarStyleDefault animated:isAnimate];
}

- (BOOL)gestureRecognizerShouldBegin{
    return YES;
}

- (void)showHUDInView:(NSString *)text{
    [MBProgressTool showTextForView:self.view text:text];
}

- (void)showHUDInWindow:(NSString *)text{
    [MBProgressTool showTextForView:[UIApplication sharedApplication].keyWindow text:text];
}

- (void)showLoadingInView{
    [MBProgressTool showLoadingForView:self.view];
}

- (void)showLoadingInWindow{
    [MBProgressTool showLoadingForView:[UIApplication sharedApplication].keyWindow];
}

- (void)hideHUDInView{
    [MBProgressTool hideForView:self.view];
}

- (void)hideHUDInWindow{
    [MBProgressTool hideForView:[UIApplication sharedApplication].keyWindow];
}

- (void)logEvent:(NSString *)event{
    [FIRAnalytics logEventWithName:event
                        parameters:nil];
}

- (void)logEvent:(NSString *)event params:(NSDictionary *)params{
    [FIRAnalytics logEventWithName:event
                        parameters:params];
}

- (void)onLeftButtonTouched{
    if (self.navigationController && self.navigationController.viewControllers.count > 1) {
        [self.navigationController popViewControllerAnimated:YES];
    }
    else if (!self.navigationController){
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
